package com.chen.q1.initial;

import com.chen.q1.handler.HttpInboundHandler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * 初始化HttpInboundHandler
 * @author Charles
 */
public class HttpInitializer extends ChannelInitializer<SocketChannel> {
    private final String proxiedServer;

    public HttpInitializer(String proxiedServer) {
        this.proxiedServer = proxiedServer;
    }

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline p = ch.pipeline();
        p.addLast(new HttpServerCodec());
        p.addLast(new HttpObjectAggregator(1024 * 1024));
        p.addLast(new HttpInboundHandler(proxiedServer));
    }

}
